import Vue from 'vue'
import Router from 'vue-router'
import Layout from '@/layout/index.vue'

Vue.use(Router)

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/register',
    component: () => import('@/views/register/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404.vue'),
    hidden: true
  },

  { path: '*', redirect: '/404', hidden: true },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },

  {
    path: '/courseManager',
    component: Layout,
    // meta: {title: '课程管理', icon: 'el-icon-message'},
    children: [
      {
        path: 'index',
        name: 'Index',
        component: () => import('@/views/courseManager/index'),
        meta: { title: '管理课程', icon: 'el-icon-message' }
      },
      {
        path: 'module/currentSelCourse',
        name: 'CurrentSelCourse',
        component: () => import('@/views/courseManager/module/currentSelCourse.vue'),
        meta: { title: '管理当前选课', icon: 'el-icon-message' },
        hidden: true
      }
    ]
  },

  {
    path: '/studentSelCourse',   // 一级路由
    component: Layout,
    // meta: {title: '课程管理', icon: 'el-icon-message'},
    children: [
      {
        path: '/studentSelCourse',
        name: 'StudentSelCourse',
        component: () => import('@/views/studentSelCourse/index'),
        meta: { title: '学生选课', icon: 'el-icon-message' }
      },
      {
        path: 'module/currentSelectedCourse',   // 是否是二级路由
        name: 'CurrentSelectedCourse',
        component: () => import('@/views/studentSelCourse/module/currentSelectedCourse.vue'),
        meta: { title: '管理当前选课', icon: 'el-icon-message' },
        hidden: true
      }
    ]
  }

]
const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})
const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
